<template>
    <div class="app-container">
        <!-- 添加或修改定位器对话框 -->
        <com-dialog :title="title" :visible="open" :width="'500px'" :footer="false"
            @update:visible="(v) => { this.open = v }">
            <div slot="content">
                <el-form ref="form" :model="form" :rules="rules" label-width="100px">
                    <el-form-item label="直播事件" prop="event">
                        <el-select v-model="form.event" placeholder="请选择直播事件">
                            <el-option v-for="(item, index) in eventOpt" :key="index" :value="item.value"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="事件内容" prop="eventmsg" v-if="form.event == '用户评论' || form.event == '用户送礼'">
                        <el-input v-model="form.eventmsg" placeholder="请输入事件内容" />
                    </el-form-item>
                    <el-form-item label="触发功能" prop="funcname">
                        <el-select v-model="form.funcname" placeholder="请选择事件内容">
                            <el-option v-for="item  in funcnameOptions" :key="item.Name" :value="item.Name"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="执行次数" prop="runnum">
                        <el-input-number v-model="form.runnum" :min="1"></el-input-number>
                    </el-form-item>
                </el-form>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <!-- 有id不显示 -->
                <!-- <el-button type="primary" @click="nextSubmit" v-if="!form.id">继续提交</el-button> -->
                <el-button type="primary" @click="cancel">取 消</el-button>
            </div>
        </com-dialog>
    </div>
</template>

<script>
import ComDialog from "@/components/ComDialog";
import { IndexSubmit, GetfunciotnList, IndexUpdate, GetindexInfo } from '../../../../wailsjs/go/main/App'

export default {
    components: { ComDialog },
    name: "GpsLocatorInfoOpt",
    data() {
        return {
            // 人员类型字典
            eventOpt: [
                {
                    value: '用户进入',

                },
                {
                    value: '用户评论',

                },
                {
                    value: '用户点赞',
                },
                {
                    value: '用户送礼',
                },
                {
                    value: '用户关注',
                }
            ],
            funcnameOptions: [

            ],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 表单参数
            form: {
                event: null,
                eventmsg: null,
                funcname: null,
                runnum: null,
            },
            // 表单校验
            rules: {
                event: [
                    { required: true, message: "请选择", trigger: "blur" }
                ],
                eventmsg: [
                    { required: true, message: "请选择", trigger: "blur" }
                ],
                // funcname: [
                //     { required: true, message: "请选择", trigger: "blur" }
                // ],
                funcname: [
                    { required: true, message: "不能为空", trigger: "blur" }
                ],
            }
        }
    },
    mounted() {
        GetfunciotnList().then(res => {
            this.funcnameOptions = JSON.parse(res);
        })
    },
    methods: {
        // changeForm(e, value) {
        //     this.form.funcname = this.funcnameOptions.filter(item => item.Id == value)[0].name;
        // },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 继续提交
        nextSubmit() {

        },
        // 表单重置
        reset() {
            this.form = {
                event: null,
                eventmsg: null,
                funcname: null,
                // funcid: null,
                runnum: 1,
            };
            this.$forceUpdate();
            // this.$refs.form.resetField();
            // this.$refs.form.clearValidate();
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.open = true;
            this.$forceUpdate();
            this.reset();
            this.title = "新增事件";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.title = "修改事件";
            this.reset();
            GetindexInfo(row.ID).then(res => {
                this.form = JSON.parse(res);
                this.open = true;
                this.$forceUpdate();

                // Object.assign(this.form, row);
            })
        },
        /** 提交按钮 */
        submitForm() {
            let _this = this;
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (_this.form.ID) {
                        IndexUpdate(JSON.stringify(_this.form)).then(res => {
                            // 1的时候成功
                            if (res == '1') {
                                this.open = false;
                                this.$emit('getList')
                            } else {

                            }
                        })
                    } else {
                        IndexSubmit(JSON.stringify(_this.form)).then(res => {
                            // 1的时候成功
                            if (res == '1') {
                                this.open = false;
                                this.$emit('getList')
                            } else {

                            }
                        })
                    }
                }
            });
        }
    }
};
</script>
  